package com.weiyv.Updater.utils;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;

public class MiscFunc {
    public static HashMap<String, Object> Json2HashMap(String JSONString, String[] key) {
        HashMap<String, Object> hashMap = new HashMap<String, Object>();
        try {
            JSONObject result = new JSONObject(JSONString);
            for (int i = 0; i < key.length; i++) {
                if (result.has(key[i])) {
                    hashMap.put(key[i], result.get(key[i]));
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return hashMap;
    }
}
